package com.dragon.concurrent.demo.interrupt;

/**
 * @author dragon
 * @version V1.0.0-RELEASE
 * @date 2019/6/1 18:23
 */
public class ThreadInterruptTest1 {
    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        myThread.start();
        Thread.sleep(3000);
        myThread.interrupt();
    }
}

class MyThread extends Thread {

    @Override
    public void run() {
        while (true) {
            if (Thread.interrupted()) {
                System.out.println("有人吵醒我,说要中断我,给我了一个中断信号");
            } else {
                System.out.println("正常执行");
            }
        }
    }
}
